/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package utils;

import java.awt.Component;
import java.awt.Container;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JTextField;

/**
 * Reseter
 * @author Spazee
 */
public class Reseter {

    /**
     * Rest child controls (TextField and ComboBox)
     * @param form
     */
    public static void resetForm(JFrame form){
        Container cont = form.getContentPane();
        int n = cont.getComponentCount();

        for(int i = 0; i < n; i++){
            Component comp = cont.getComponent(i);

            if(((comp.getClass()).getName()).compareTo("javax.swing.JTextField") == 0){
                JTextField txtBox = new JTextField();
                txtBox = (JTextField)comp;
                
                txtBox.setText("");
                cont.remove(comp);
                cont.add(txtBox, i);
            }
            else if(((comp.getClass()).getName()).compareTo("javax.swing.JComboBox") == 0) {
                JComboBox cbBox = new JComboBox();
                cbBox = (JComboBox)comp;

                if(cbBox.getItemCount() != 0){
                    cbBox.setSelectedIndex(0);
                    cont.remove(comp);
                    cont.add(cbBox, i);
                }
            }
        }

        
    }

}
